﻿namespace Innovative.ProXr
{
	public static partial class DirectApi
	{
		/// <summary>
		/// Some ProXR Series Enhanced Controllers support control of up to 256 potentiometers.
		/// A potentiometer is a variable resistor, capable of changing resistance
		/// under software control. Programmable potentiometers are ideal for making computer
		/// controlled mixers and audio/video mixing devices, as well as light dimmers
		/// and motor speed controllers. The POT and UPOT series controllers offer RS-232
		/// and USB controlled potentiometers, and are ideally suited for integration into
		/// various types of test instruments, programmable amplifiers, programmable power
		/// supplies, and anything else that can benefit by software controlled resistance
		/// variation. As a general rule, potentiometer devices often require external circuitry.
		/// For instance, it is not possible to control the brightness of a light bulb directly or
		/// the speed of a motor without some additional electronics.<br/>
		/// Potentiometer controllers are available with 10K, 50K and 100K programmable
		/// potentiometers. It is possible to set the power-up default state of the first 48
		/// potentiometers. It is also possible to control each potentiometer in 256 steps,
		/// allowing fine adjustments under software control. You can control up to 256
		/// potentiometers under software control, you can control each individually or all
		/// simultaneously. In addition to potentiometer control the POT and UPOT series
		/// controllers include the ProXR command set, allowing you to plug in up to 256
		/// relays into the expansion port.<br/>
		/// Potentiometers have 3 Connections: A, Wiper, and B. When a low value is sent to
		/// the controller, the wiper moves closer to A, decreasing the resistance between A and
		/// the wiper (increasing the resistance between the wiper and B). When a high value is sent
		/// to the controller, the wiper moves closer to B, decreasing the resistance between the
		/// wiper and B (increasing the resistance between the wiper and A). The first 48
		/// channels of wiper values can be set to a power-up default state. It is possible to
		/// set the wipers on all outputs individually or simultaneously.
		/// </summary>
		public static class Potentiometer
		{
			/// <summary>
			/// This Command Sets the wiper position of the selected potentiometer to a selected
			/// value. POT has a valid value of 0-255, Value has a valid range of 0-255. A Low
			/// value move the wiper closer to A. A high value moves the wiper closer to B.
			/// </summary>
			public static RelayCommandSet<bool, int, int> SetOneValue = new RelayCommandSet<bool, int, int>()
			{
				Commands = new RelayCommand[]
				{
					RelayCommand.Command254,
					RelayCommand.CreateReadOnlyCommand(1, 170),
					RelayCommand.CreateNonOptionalParameterCommand(2, (new RelayByte[0]).CreateRange(0, 255), "POT", "Indicates the potentiometer."),
					RelayCommand.CreateNonOptionalParameterCommand(3, (new RelayByte[0]).CreateRange(0, 255), "Value", "The value of the wiper position.")
				},
				ExpectedResults = new RelayByte[] { 85 },
				ResponseConverter = new Boolean85ResponseConverter(),
				Parameter1Converter = new Int32ParameterConverter(),
				Parameter2Converter = new Int32ParameterConverter()
			};

			/// <summary>
			/// This Command Sets All wiper positions of all potentiometers to a selected value.
			/// Value has a valid range of 0-255. A Low value move the wiper closer to A. A
			/// high value moves the wiper closer to B.
			/// </summary>
			public static RelayCommandSet<bool, int> SetAllValues = new RelayCommandSet<bool, int>()
			{
				Commands = new RelayCommand[]
				{
					RelayCommand.Command254,
					RelayCommand.CreateReadOnlyCommand(1, 171),
					RelayCommand.CreateNonOptionalParameterCommand(2, (new RelayByte[0]).CreateRange(0, 255), "Value", "The value of the wiper position.")
				},
				ExpectedResults = new RelayByte[] { 85 },
				ResponseConverter = new Boolean85ResponseConverter(),
				Parameter1Converter = new Int32ParameterConverter()
			};

			/// <summary>
			/// This Command stores a Power up Default Wiper Position for the Selected Potentiometer.
			/// Pot has a valid range of 0 to 47. Value has a valid range of 0-255. A
			/// Low value move the wiper closer to A. A high value moves the wiper closer to B.
			/// </summary>
			public static RelayCommandSet<bool, int, int> StoreOneStartupValue = new RelayCommandSet<bool, int, int>()
			{
				Commands = new RelayCommand[]
				{
					RelayCommand.Command254,
					RelayCommand.CreateReadOnlyCommand(1, 172),
					RelayCommand.CreateNonOptionalParameterCommand(2, (new RelayByte[0]).CreateRange(0, 47), "POT", "Indicates the potentiometer."),
					RelayCommand.CreateNonOptionalParameterCommand(3, (new RelayByte[0]).CreateRange(0, 255), "Value", "Store this value as the wiper startup position.")
				},
				ExpectedResults = new RelayByte[] { 85 },
				ResponseConverter = new Boolean85ResponseConverter(),
				Parameter1Converter = new Int32ParameterConverter(),
				Parameter2Converter = new Int32ParameterConverter()
			};

			/// <summary>
			/// This Command reads the Power up Default Wiper Position for the Selected Potentiometer.
			/// Pot has a valid range of 0 to 47. This command returns a single byte of
			/// data indicating the power up default Wiper position of the selected potentiometer.
			/// </summary>
			public static RelayCommandSet<bool, int> ReadStoredStartupValue = new RelayCommandSet<bool, int>()
			{
				Commands = new RelayCommand[]
				{
					RelayCommand.Command254,
					RelayCommand.CreateReadOnlyCommand(1, 173),
					RelayCommand.CreateNonOptionalParameterCommand(2, (new RelayByte[0]).CreateRange(0, 47), "POT", "Indicates the potentiometer.")
				},
				ExpectedResults = (new RelayByte[0]).CreateRange(0, 255),
				ResponseConverter = new Boolean85ResponseConverter(),
				Parameter1Converter = new Int32ParameterConverter()
			};
		}
	}
}
